package com.chandra.pos.customer.dao.entity;

import com.chandra.pos.common.model.TransactionType;
import org.joda.time.DateTime;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

/**
 * Created by Admin on 8/15/14.
 */
public interface TransactionRepository extends JpaRepository<TransactionEntity, Long> {


    public Page<TransactionEntity> findByCustomerId(Long customerId, Pageable pageable);


    @Query("SELECT p FROM TransactionEntity p WHERE p.transactionType = :transactionType and  p.transactionDate between :startDate and :endDate")
    public Page<TransactionEntity> search(@Param("transactionType") TransactionType transactionType, @Param("startDate") DateTime startDate, @Param("endDate") DateTime endDate, Pageable pageable);

    @Query("SELECT p FROM TransactionEntity p WHERE  p.transactionDate between :startDate and :endDate")
    public Page<TransactionEntity> search( @Param("startDate") DateTime startDate, @Param("endDate") DateTime endDate, Pageable pageable);

    @Query("SELECT p FROM TransactionEntity p WHERE p.transactionType = :transactionType ")
    public Page<TransactionEntity> search(@Param("transactionType") TransactionType transactionType, Pageable pageable);



    @Query("SELECT p FROM TransactionEntity p WHERE p.customerId = :customerId and p.transactionType = :transactionType and  p.transactionDate between :startDate and :endDate")
    public Page<TransactionEntity> search(@Param("customerId") Long customerId,@Param("transactionType") TransactionType transactionType, @Param("startDate") DateTime startDate, @Param("endDate") DateTime endDate, Pageable pageable);

    @Query("SELECT p FROM TransactionEntity p WHERE p.customerId = :customerId and p.transactionDate between :startDate and :endDate")
    public Page<TransactionEntity> search( @Param("customerId") Long customerId,@Param("startDate") DateTime startDate, @Param("endDate") DateTime endDate, Pageable pageable);

    @Query("SELECT p FROM TransactionEntity p WHERE p.customerId = :customerId and p.transactionType = :transactionType ")
    public Page<TransactionEntity> search(@Param("customerId") Long customerId,@Param("transactionType") TransactionType transactionType, Pageable pageable);

}
